package com.example.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Slf4j
@Configuration
public class ApplicationStoreConfigure implements WebMvcConfigurer {

    @Value("${store.root-path}")
    private String rootPath;

    @Resource
    private Environment env;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        log.info(rootPath);
//        log.info(rootPath + env.getProperty("store.protected-folder"));
        registry.addResourceHandler("/images1/**").addResourceLocations("file:" + rootPath + env.getProperty("store.public-folder") + "/");
        registry.addResourceHandler("/images2/**").addResourceLocations("file:" + rootPath + env.getProperty("store.protected-folder") + "/");
    }
}
